<!DOCTYPE html>
<html>
	<head>
		<link rel="stylesheet" href="../../../codebase/webix.css" type="text/css" media="screen" charset="utf-8">
		<script src="../../../codebase/webix.js" type="text/javascript" charset="utf-8"></script>
		<style>
			#areaA, #areaB{
				margin: 30px;
			}
		</style>
		<title>Validation with a Complex Rule</title>
	</head>
	<body>

		<form>
			<div id="areaA"></div>
			<div id="areaB"></div>
		</form>
	

		<script type="text/javascript" charset="utf-8">
		var form1 = [
			{ view:"text", label:'Login', name:"login" },
			{ view:"text", label:'Email', name:"email" },
			{ view:"button", value: "Submit", click:function(){
				var form = this.getParentView();
				if (form.validate())
					webix.message("All is correct");
				else
					webix.message({ type:"error", text:"Form data is invalid" });
			}}
		];


		webix.ui({
			container:"areaA",
			view:"form", scroll:false, width:300, 

			elements: form1,
			rules:{
				$obj:function(){
					var data = this.getValues();

					if (!webix.rules.isEmail( data.email )) return false;
					if (data.name == "") return false;
					return true;
				}
			},
			elementsConfig:{
				labelPosition:"top"
			}
		});	

		</script>
	</body>
</html>